<template>
  <views class="company_list">
    <viewTitle :title="'企业列表'"></viewTitle>
    <div class="search">
      <el-form ref="form" label-width="auto" :inline="true">
        <el-form-item label="企业名称:">
          <el-input type="text" clearable placeholder="请输入企业名称" v-model="company_name"></el-input>
        </el-form-item>
        <el-form-item label="企业类型:">
          <el-select v-model="company_type" clearable placeholder="请选择">
            <el-option
                    v-for="item in company_type_list"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="统一社会信用代码:">
          <el-input type="text" clearable placeholder="请输入信用代码" v-model="organization_code"></el-input>
        </el-form-item>
        <el-form-item label="法人姓名:">
          <el-input type="text" clearable placeholder="请输入法人姓名" v-model="legal_person"></el-input>
        </el-form-item>

        <el-form-item label="法人联系方式:">
          <el-input type="text" clearable placeholder="请输入联系方式" v-model="legal_phone"></el-input>
        </el-form-item>
        <el-form-item label="法人身份证号:">
          <el-input type="text" clearable placeholder="请输入身份证号" v-model="legal_card_no"></el-input>
        </el-form-item>
        <el-form-item label="注册时间:">
          <el-date-picker
                  v-model="registration_date"
                  type="datetimerange"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
          ></el-date-picker>
        </el-form-item>
      </el-form>
      <div class="btn-area">
        <el-button type="primary" @click="getData">查询</el-button>
        <el-button @click="reset">重置</el-button>
        <el-button type="warning" v-if="$route.query.check.i" @click="add">新增</el-button>
      </div>
    </div>
    <div class="table_list">
      <el-table :data="tableList" border style="width: 100%" :header-cell-style="getRowClass">
        <el-table-column type="index" label="序号" width="100"></el-table-column>
        <!-- <el-table-column prop="company_id" label="ID" width="180"></el-table-column> -->
        <el-table-column prop="company_name" label="企业名称" width="180"></el-table-column>
        <el-table-column :formatter="(row) => {return  row.type == 1 ? '快递' : '物流'}" label="企业类型" width="180"></el-table-column>
        <el-table-column prop="organization_code" label="统一社会信用代码" width="200"></el-table-column>
        <el-table-column prop="legal_person" label="法人" width="180"></el-table-column>
        <el-table-column prop="legal_phone" label="法人联系方式" width="150"></el-table-column>
        <el-table-column prop="legal_card_no" label="法人身份证号" width="200"></el-table-column>
        <el-table-column prop="create_time" label="注册时间" width="200"></el-table-column>

        <!-- <el-table-column prop="empnum" label="揽件人数" width="150"></el-table-column> -->
        <el-table-column label="揽件人数" width="130">
              <template slot-scope="scope">
             <!-- <router-link>{{scope.row.empnum}}</router-link> -->
              <el-button size="mini"  @click="opendetail(scope.row.company_id)" style="border: none; color:#409EFF">{{scope.row.empnum}}</el-button>
              </template>
            </el-table-column>
        <el-table-column fixed="right" label="操作" width="320">
          <template slot-scope="scope">
            <el-button   v-if="$route.query.check.m" @click="look(scope.row.company_id)" icon="el-icon-search">详情</el-button>
            <el-button type="primary"  v-if="$route.query.check.m" @click="edit(scope.row.company_id)" icon="el-icon-edit">修改</el-button>
            <el-button type="danger"  v-if="$route.query.check.d" @click="deleted(scope.row.company_id)" icon="el-icon-delete">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="flex flexR paging">
        <el-pagination
          style="background:#fff; padding:10px 0"
          background
          layout="prev, pager, next,sizes,total, jumper"
          @size-change="(page_size) => {this.pagination.page_size = page_size;this.getData()}"
          @current-change="(current_page) => {this.pagination.page_start = current_page;this.getData()}"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="pagination.page_size"
          :total="pagination.total_count"
          :current-page="pagination.current_page"
          :page-count="pagination.page_count"
        ></el-pagination>
      </div>
    </div>
  </views>
</template>
<script>
export default {
  data() {
    return {
      company_name: "", // 企业名称
      organization_code: "", // 信用代码
      legal_person: "", // 法人名称
      legal_phone: "", // 联系方式
      legal_card_no: "", // 身份证
      tableList: [],
      pagination: {
        page_start: 0, //搜索开始页码
        current_page: 0, //当前页码
        page_count: 0, //总页数
        page_size: 10, //每页数量
        total_count: 0 //总数量
      },
      empnum: "", // 揽件员人数
      company_type: null,
      company_type_list: [
        {value:null, label:'全部'},
        {value:0, label:'物流'},
        {value:1, label:'快递'}
      ],
      registration_date: [], // 注册时间
    };
  },
  computed: {
    postData(){
      let post = {};
      post.company_name = this.company_name;
      post.empnum = this.empnum;
      post.organization_code = this.organization_code;
      post.legal_person = this.legal_person;
      post.legal_phone = this.legal_phone;
      post.legal_card_no = this.legal_card_no;
      post.pagination = this.pagination;
      if(this.registration_date.length > 0){
        post.start_created_time = this.registration_date[0]/1000;     //开始时间
        post.end_created_time = this.registration_date[1]/1000;     //结束时间
      }
      post.type = this.company_type;
      return  post;
    }
  },

  methods: {
    //    修改第一行样式
    getRowClass({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return "background: #FAFAFA ";
      } else {
        return "";
      }
    },
    //    修改是否换行
    opendetail(company_id){
     this.$toRoutePath({
        path: "/employee_list",
        edit: true,
        query: { checktype: 1 ,company_id:company_id}
      });
    },
    changeStyleRow(width) {
      let _width = width - 290 - 350 - 300 - 50 - 25;
      if (_width > 300) {
        this.marginLeft = 25;
      } else {
        this.marginLeft = 0;
      }
    },
    // 获取数据

    getData() {
       this.$raxios.post(this.$mapapi.companyList, {data:this.postData}).then(res=>{
         if(res.code==200){
           this.tableList = res.data.list;
           this.pagination = res.data.pagination;
         }else{
	         this.$message.error(res.msg)
         }
       }).catch(res=>{
            this.tableList = [];
          this.pagination = [];
       })
    },
    // 查看
    look(company_id){
      this.$toRoutePath({
        path: "/company_list/company_look",
        edit: true,
        query: {company_id}
      });

    },
    // 修改
    edit(company_id) {
        console.log('company_id', company_id);
      this.$toRoutePath({
        path: "/company_list/company_amend",
        edit: true,
        query: {company_id}
      });
    },
    // 删除
    deleted(company_id) {
      let post_data={
        company_id:company_id
      }
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$raxios.post(this.$mapapi.delCompany, {data:post_data}).then(res=>{
            if(res.code==200){
            this.$message.success("删除成功!");
            this.getData();
            }else{
               this.$message.error(res.msg);
               return  ;
            }
          })      
        })
        .catch(() => {
          this.$message.info("已取消删除");
        });
    },
    // 重置
    reset() {
       this.company_name = ""; // 企业名称
       this.organization_code = ""; // 信用代码
       this.legal_person = ""; // 法人名称
       this.legal_phone = ""; // 联系方式
       this.legal_card_no = ""; // 身份证
      this.registration_date = []; // 注册时间
      this.company_type = null; // 企业类型
      this.getData()
    },
    // 新增
    add() {
      this.$toRoutePath({
        path: "/company_list/company_add",
        edit: true,
        query: {}
      });
    }
  },
  mounted() {
    this.getData();
  },
  created() {}
};
</script>





<style lang="less" :scope="true"  src="@/style/company_manager/company_list.less">
</style>
